##############################
#   角色函数   
#   by Jerry Yang      
#   UUZ0226            
#############################
from random import randrange
from gametext import GameText

def pro(stats):
    inf = stats.inf
    L = randrange(1,99)
    M = randrange(50,99)
    D = randrange(1,50)
    A = randrange(10,99)
    inf['Attack'] = A
    inf['Defend'] = D
    inf['Magic'] = M
    inf['Lucky'] = L
    stats.inf = inf

def welcome(stats):
    inf = stats.inf
    Skill = stats.Skill
    pro(stats)
    inf['Level'] = 1
    inf['Exp'] = 0
    Skill['二连击'] = {
            'SkillMagic':10,
            'SkillAttack':inf['Attack']*2,
    }
    exp(stats)
    hp(stats)
    stats.inf = inf
    stats.Skill = Skill

def hp(stats):
    level = stats.inf['Level']
    blood_volume = level*100
    stats.inf['Hp'] = blood_volume

def exp(stats):
    level = stats.inf['Level']
    stats.inf['ExpMax'] = 10*level

def show_information(ai_settings,screen,stats,location):
    inf = stats.inf
    A = inf['Attack']
    D = inf['Defend']
    M = inf['Magic']
    L = inf['Lucky']
    H = inf['Hp']
    Lv = inf['Level']
    E = inf['Exp']
    Em = inf['ExpMax']
    text = ['攻击：'+ str(A),
            '防御：'+ str(D),
            'HP：'+ str(H),
            'MP：'+ str(M),
            '幸运：'+ str(L),
            '等级：'+ str(Lv),
            '经验：'+ str(E) + '/' + str(Em)
            ]
    for  i in range(0, len(text)):
        if i == 2:
            ai_settings.text_color = (255, 0, 0)
        elif i == 3:
            ai_settings.text_color = (0, 0,255)
        else:
            ai_settings.text_color = (30,30,30)
        if location == 'center':
            m = show_in_center(ai_settings, screen,text,i)
        elif location == 'left':
            m = show_in_left(ai_settings, screen,text,i)


def show_in_center(ai_settings, screen,text,i):
    m = GameText(ai_settings, screen,text[i],20)
    m.welcome_rect.centerx = m.screen_rect.centerx
    m.welcome_rect.centery = m.screen_rect.centery + (i-4)*20
    m.show_welcome()

def show_in_left(ai_settings, screen,text,i):
    m = GameText(ai_settings, screen,text[i],20)
    m.welcome_rect.bottom = m.screen_rect.bottom - (i+1)*30
    m.welcome_rect.left = m.screen_rect.left 
    m.show_welcome()

def show_in_right(ai_settings, screen,text,i):
    m = GameText(ai_settings, screen,text[i],20)
    m.welcome_rect.top = m.screen_rect.top + (i+1)*30
    m.welcome_rect.right = m.screen_rect.right -30
    m.show_welcome()


